package v1

import (
	"gin-vue-admin/global"
	"gin-vue-admin/model"
	"gin-vue-admin/model/request"
	"gin-vue-admin/model/response"
	"gin-vue-admin/service"
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
)

// @Tags UserGoods
// @Summary 创建UserGoods
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.UserGoods true "创建UserGoods"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /userGoods/createUserGoods [post]
func CreateUserGoods(c *gin.Context) {
	var userGoods model.UserGoods
	_ = c.ShouldBindJSON(&userGoods)
	if err := service.CreateUserGoods(userGoods); err != nil {
        global.GVA_LOG.Error("创建失败!", zap.Any("err", err))
		response.FailWithMessage("创建失败", c)
	} else {
		response.OkWithMessage("创建成功", c)
	}
}

// @Tags UserGoods
// @Summary 删除UserGoods
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.UserGoods true "删除UserGoods"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /userGoods/deleteUserGoods [delete]
func DeleteUserGoods(c *gin.Context) {
	var userGoods model.UserGoods
	_ = c.ShouldBindJSON(&userGoods)
	if err := service.DeleteUserGoods(userGoods); err != nil {
        global.GVA_LOG.Error("删除失败!", zap.Any("err", err))
		response.FailWithMessage("删除失败", c)
	} else {
		response.OkWithMessage("删除成功", c)
	}
}

// @Tags UserGoods
// @Summary 批量删除UserGoods
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.IdsReq true "批量删除UserGoods"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"批量删除成功"}"
// @Router /userGoods/deleteUserGoodsByIds [delete]
func DeleteUserGoodsByIds(c *gin.Context) {
	var IDS request.IdsReq
    _ = c.ShouldBindJSON(&IDS)
	if err := service.DeleteUserGoodsByIds(IDS); err != nil {
        global.GVA_LOG.Error("批量删除失败!", zap.Any("err", err))
		response.FailWithMessage("批量删除失败", c)
	} else {
		response.OkWithMessage("批量删除成功", c)
	}
}

// @Tags UserGoods
// @Summary 更新UserGoods
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.UserGoods true "更新UserGoods"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
// @Router /userGoods/updateUserGoods [put]
func UpdateUserGoods(c *gin.Context) {
	var userGoods model.UserGoods
	_ = c.ShouldBindJSON(&userGoods)
	if err := service.UpdateUserGoods(userGoods); err != nil {
        global.GVA_LOG.Error("更新失败!", zap.Any("err", err))
		response.FailWithMessage("更新失败", c)
	} else {
		response.OkWithMessage("更新成功", c)
	}
}

// @Tags UserGoods
// @Summary 用id查询UserGoods
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.UserGoods true "用id查询UserGoods"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /userGoods/findUserGoods [get]
func FindUserGoods(c *gin.Context) {
	var userGoods model.UserGoods
	_ = c.ShouldBindQuery(&userGoods)
	if err, reuserGoods := service.GetUserGoods(userGoods.ID); err != nil {
        global.GVA_LOG.Error("查询失败!", zap.Any("err", err))
		response.FailWithMessage("查询失败", c)
	} else {
		response.OkWithData(gin.H{"reuserGoods": reuserGoods}, c)
	}
}

// @Tags UserGoods
// @Summary 分页获取UserGoods列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.UserGoodsSearch true "分页获取UserGoods列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /userGoods/getUserGoodsList [get]
func GetUserGoodsList(c *gin.Context) {
	var pageInfo request.UserGoodsSearch
	_ = c.ShouldBindQuery(&pageInfo)
	if err, list, total := service.GetUserGoodsInfoList(pageInfo,`id desc`); err != nil {
	    global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
        response.FailWithMessage("获取失败", c)
    } else {
    	dsh,shbh,shtg:= service.GetGoodsTotalInfo(pageInfo)
        response.OkWithDetailed(response.PageResult{
        	Dsh: dsh,
        	Shbh: shbh,
        	Shtg: shtg,
            List:     list,
            Total:    total,
            Page:     pageInfo.Page,
            PageSize: pageInfo.PageSize,
        }, "获取成功", c)
    }
}
